package iedcyt.acute.controller.listeners.maesorgPublication;

import iedcyt.acute.businessServices.ViewLogger;
import iedcyt.acute.model.MaesorgPublicationModel;
import iedcyt.acute.view.MaesorgPublicationView;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

public class CandidatesKeyDownListener implements Listener {

	private MaesorgPublicationModel _model;
	private MaesorgPublicationView _view;
	
	public CandidatesKeyDownListener(MaesorgPublicationView view, MaesorgPublicationModel model) {
		this._model = model;
		this._view = view;
	}
	
	@Override
	public void handleEvent(Event event) {

		char press = ("" + event.character).toLowerCase().toCharArray()[0];
		
		// al pulsar 'n' se normaliza la publicacion con ABV_corregido del candidato
		if (press == 'n') {
			_model.normalizeWithCandidate();
			
			updateView_c();
		} else if (press == 'h') {
			ViewLogger.getInstance().info("Al pulsar'n' se normaliza la publicacion con ABV_corregido del candidato");
		}
	}

	private void updateView_c() {
		_view.loadPublication(_model.getPublications());
		_view.loadCandidates(_model.getCandidates());
		_view.loadPublication_jsss(_model.getNoABV_posibles_jsss());
		_view.loadCandidates_jsss(_model.getCandidate_jsss());
	}
}
